import sys

sys.path.append('../..')
from common.config import *
from db.mysql import MysqlClient
from itertools import product
from urllib.parse import urlencode
import requests, time
from common.helper import Helper
import pandas as pd
class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "珍爱e生特定疾病海外医疗保险"

    # 生成产品数据
    def genProductInfo(self):
        # 价格表
        price_list =  ["464", "640", "960", "1520", "2160", "2720", "3075", "3225", "3525", "3675", "3750", "3825",
                       "3900", "3975"]
        plan = {
            # 年龄段
            "year": ["0-17", "18-25", "26-30", "31-35", "36-40", "41-45", "46-50", "51-55", "56-60", "61-65", "66-70",
                     "71-75", "76-80", "81-85"],
            #保障金额
            "money":["6000000"],
            #保障期限
            "expire":["1年"],
            #交费类型
            "payType":["年交"],

        }
        num = 0
        for v in product(plan["year"],plan["money"],plan["expire"],plan["payType"]):
            data = Helper.formatProductInfo( plan,v )
            data["price"] = Helper.decimalParse( price_list[num] )
            num += 1
            self.mysql.cursor.execute(domain[self.name]["insert_sql"].format( **data ))
            self.mysql._conn.commit()
            print( domain[self.name]["insert_sql"].format( **data ) )




